package day03;

import java.util.Scanner;

/**
 * 
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 * @date 2010-2-5
 */
public class HotelRoomManagement {
	public static void main(String[] args) {
		String[][] rooms = new String[10][12];
		for (int i = 0; i < rooms.length; i++) {
			for (int j = 0; j < rooms[i].length; j++) {
				rooms[i][j] = "EMPTY";
			}
		}
		Scanner sca = new Scanner(System.in);
		while (true) {
			System.out.println("Please enter your command:");
			String command = sca.next();
			if (command.equals("search")) {
				for (int i = 0; i < rooms.length; i++) {
					for (int j = 0; j < rooms[i].length; j++) {
						System.out.print((i + 1) * 100 + (j + 1) + "\t");
					}
					System.out.println();
					for (int j = 0; j < rooms[i].length; j++) {
						System.out.print(rooms[i][j] + "\t");
					}
					System.out.println();
					System.out.println();
				}
			} else if (command.equals("in")) {
				System.out.println("Plesae enter your room number:");
				int roomid = sca.nextInt();
				String guestName = sca.next();
				int i = roomid / 100 - 1;
				int j = roomid % 100 - 1;
				if (i < 0 || i > rooms.length - 1 || j < 0
						|| j > rooms[0].length - 1) {
					System.out.println("房间编号不正确，请重新输入");
					continue;
				}
				if (rooms[i][j].equals("EMPTY")) {
					rooms[i][j] = guestName;
					System.out.println(guestName + "成功入主" + roomid);
				} else {
					System.out.println(roomid + "房间已经有人入主");
				}
				System.out.println();
			} else if (command.equals("out")) {
				System.out.println("退房系统已开启，请输入你要退掉的房号：");
				int roomid = sca.nextInt();
				int i = roomid / 100 - 1;
				int j = roomid % 100 - 1;
				if (i < 0 || i > rooms.length - 1 || j < 0
						|| j > rooms[0].length - 1) {
					System.out.println("房间编号不正确，请重新输入");
					continue;
				}
				if (rooms[i][j].equals("EMPTY")) {
					System.out.println(roomid + "你要退定的房间无人在住：");
				} else {
					rooms[i][j] = "EMPTY";
					System.out.println("退房成功，欢迎下次再来。");
				}
			} else if (command.equals("quit")) {
				System.out.println("Goodbye!");
				break;
			} else {
				System.out.println("Your command is wrong!Plesae renter is");
			}
		}
	}
}